<script>
    // 实现深copy
    function deepClone(target, weakMap = new WeakMap()) {
        if (target == null) return target;
        if (target instanceof Date) return new Date(target);
        if (target instanceof RegExp) return new RegExp(target)
        // .....

        if (typeof target !== "object") return target;
        let cloneTarget = new target.constructor;

        if (weakMap.get(target)) {
            return weakMap.get(target)
        }

        weakMap.set(target, cloneTarget)
        for (let key in target) {
            if (target.hasOwnProperty(key)) {
                cloneTarget[key] = deepClone(target[key], weakMap)
            }
        }
        return cloneTarget;
    }
    let obj = { name: "码路", address: { city: "北京" } };
    obj.xxx = obj; // 循环引用
    let newObj = deepClone(obj);
    console.log(newObj);
</script>